package com.juc.learn;

import com.juc.learn.callable.CallableDemo;
import com.juc.learn.runnable.RunnableDemo;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * ClassName:Test
 * Package:com.juc.learn
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/27 - 10:49
 * @Version:v1.0
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //Runnable方式创建线程
        new Thread(new RunnableDemo(),"线程1").start();
        //Callable方式创建线程
        FutureTask<Integer> task1 = new FutureTask<>(new CallableDemo());
        FutureTask<Integer> task2 = new FutureTask<>(()->{
            Thread.sleep(5000);
            System.out.println(Thread.currentThread().getName()+" come in callable");
            return 1024;
        });
        new Thread(task1,"线程2").start();
        new Thread(task2,"线程3").start();
        System.out.println(task1. get());
        System.out.println(task2.get());//会主阻塞的获取

    }
}
